package com.woniuxy.background.job;

import com.woniuxy.background.pojo.Log;
import com.woniuxy.background.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@Component
public class LogScheduler {

    @Value("${scheduler.log.days}")
    private Integer days;

    @Autowired
    private LogService logService;

    public void deleteLog(){
        Calendar now = Calendar.getInstance();
        now.add(Calendar.DAY_OF_YEAR,-days);
        int count = logService.deleteLog(now.getTime());
        //记录系统删除日志数据的日志
        Log log = new Log();
        log.setIp("");
        log.setUsername("系统自动任务");
        log.setCreateTime(new Date());
        log.setOperation("系统删除日志["+count+"]条数据");
        log.setMethod("");
        log.setParams("");
        logService.saveLog(log);

    }












}
